//use crate::prelude::*;
use core::panic::PanicInfo;

#[panic_handler]
#[no_mangle]
fn panic(panic_info: &PanicInfo) -> ! {
    // 使用write!以捕获双重错误
    write!(get_serial(), "[PANIC] panic() called\n\r").unwrap_or_else(|_| {
        double_fault();
    });
    write!(
        get_serial(),
        "panic occurred: {}",
        panic_info
            .message()
            .unwrap_or(&format_args!("***NO MESSAGE***"))
    )
    .unwrap_or_else(|_| {
        double_fault();
    });;
    if let Some(location) = panic_info.location() {
        write!(get_serial(), "location: {}", location).unwrap_or_else(|_| {
            double_fault();
        });
    }
    die()
}

#[lang = "eh_personality"]
#[no_mangle]
pub extern "C" fn rust_eh_personality() {}
